import 'package:flutter/material.dart';

class PopupmenuDemo extends StatefulWidget {
  PopupmenuDemo({Key key}) : super(key: key);

  _PopupmenuDemoState createState() => _PopupmenuDemoState();
}

class _PopupmenuDemoState extends State<PopupmenuDemo> {
  String _currentmenuitem = 'item1';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('PopupmenuDemo'),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(_currentmenuitem),
                Container(
                  color: Colors.redAccent,
                  
                  child: PopupMenuButton(
                    initialValue: 'item2',
                    tooltip: 'data',
                    elevation: 0.0,
                    icon: Icon(Icons.add),
                    onSelected: (v) {
                      print('onSelected : $v');
                      setState(() {
                        _currentmenuitem = v;
                      });
                    },
                    onCanceled: () {
                      print('onCanceled');
                    },
                    // offset: Offset(100.0, 10.0),
                    itemBuilder: (BuildContext context) {
                      return [
                        PopupMenuItem(
                          value: 'item1',
                          child: Text('item1'),
                        ),
                        PopupMenuItem(
                          value: 'item2',
                          child: Text('item2'),
                        ),
                        PopupMenuItem(
                          value: 'item3',
                          child: Text('item3'),
                        ),
                      ];
                    },
                  ),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
